package com.company.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GetRequestController {
    @GetMapping("/info")
    public String getInfo(HttpServletRequest request){
        // 1.获取请求参数 name, age
        String paramName = request.getParameter("name");
        String paramAge = request.getParameter("age");
        // 2.获取请求方式
        String method = request.getMethod();
        // 3.获取资源请求路径
        String uri = request.getRequestURI();
        // 4.获取完整的 URL请求路径
        String url = request.getRequestURL().toString();
        // 5.获取请求头信息
        String userAgent = request.getHeader("User-Agent");

        return "请求方式: " + method +
                "\n路径: " + uri +
                "\n完整路径: " + url +
                "\n参数 name: " + paramName +
                "\n参数 age: " + paramAge +
                "\nUser-Agent: " + userAgent;
    }
}
